﻿package net.wangit.jdbc.database;

import net.wangit.jdbc.JDBCException;

public class Informix extends Database {

	public Informix() {
		registerType(1, 1, "CHAR($p)");
		registerType(2, 12, "VARCHAR($p)");
		registerType(11, 5, "SMALLINT");
		registerType(12, 4, "INTEGER");
		registerType(13, -5, "INT8");
		registerType(21, 6, "FLOAT");
		registerType(22, 8, "DOUBLE");
		registerType(23, 3, "DECIMAL");
		registerType(31, 91, "DATE");
		registerType(32, 92, "DATETIME YEAR TO FRACTION(5)");
		registerType(33, 93, "DATETIME HOUR TO SECOND");
		registerType(41, -1, "CLOB");
		registerType(43, -4, "BLOB");
	}

	public int getTypeCode(int sqlTypeCode, String columnTypeName,
			int precision, int scale) throws JDBCException {
		switch (sqlTypeCode) {
		case 1: // '\001'
			return 1;

		case 12: // '\f'
			return 2;

		case 5: // '\005'
			return 11;

		case 4: // '\004'
			return 12;

		case -5:
			return 13;

		case 6: // '\006'
			return 21;

		case 8: // '\b'
			return 22;

		case 3: // '\003'
			return 23;

		case 91: // '['
			return 31;

		case 92: // '\\'
			return 32;

		case 93: // ']'
			return 33;

		case -1:
			return 41;

		case -4:
			return 43;
		}
		throw new JDBCException((new StringBuilder(
				"Unsupported sqlType: sqlTypeCode=")).append(sqlTypeCode)
				.append(",columnTypeName=").append(columnTypeName).toString());
	}

	public int getDefaultBatchSize() {
		return 0;
	}

	public String getAddColumnString() {
		return "add";
	}

	public boolean supportsIdentityColumns() {
		return true;
	}

	public String getIdentitySelectString() {
		return "select first 1 dbinfo('sqlca.sqlerrd1') from systables";
	}

	public String getIdentityColumnString() {
		return "SERIAL NOT NULL";
	}
}
